package com.example.controller;

import com.example.common.Result;
import com.example.entity.Review;
import com.example.service.ReviewService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评价控制器
 */
@RestController
@RequestMapping("/review")
public class ReviewController {

    @Resource
    private ReviewService reviewService;

    /**
     * 新增评价
     */
    @PostMapping("/add")
    public Result add(@RequestBody Review review) {
        reviewService.add(review);
        return Result.success();
    }

    /**
     * 更新评价
     */
    @PutMapping("/update")
    public Result update(@RequestBody Review review) {
        reviewService.update(review);
        return Result.success();
    }

    /**
     * 删除评价
     */
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        reviewService.deleteById(id);
        return Result.success();
    }

    /**
     * 根据ID查询评价
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Long id) {
        Review review = reviewService.selectById(id);
        return Result.success(review);
    }

    /**
     * 查询所有评价
     */
    @GetMapping("/selectAll")
    public Result selectAll(Review review) {
        List<Review> list = reviewService.selectAll(review);
        return Result.success(list);
    }

    /**
     * 分页查询评价列表
     */
    @GetMapping("/selectPage")
    public Result selectPage(Review review,
                           @RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Review> pageInfo = reviewService.selectPage(review, pageNum, pageSize);
        return Result.success(pageInfo);
    }

    /**
     * 根据用户ID查询评价列表
     */
    @GetMapping("/selectByUserId/{userId}")
    public Result selectByUserId(@PathVariable Long userId) {
        List<Review> list = reviewService.selectByUserId(userId);
        return Result.success(list);
    }

    /**
     * 根据酒店ID查询评价列表
     */
    @GetMapping("/selectByHotelId/{hotelId}")
    public Result selectByHotelId(@PathVariable Long hotelId) {
        List<Review> list = reviewService.selectByHotelId(hotelId);
        return Result.success(list);
    }

    /**
     * 根据预订ID查询评价
     */
    @GetMapping("/selectByBookingId/{bookingId}")
    public Result selectByBookingId(@PathVariable Long bookingId) {
        Review review = reviewService.selectByBookingId(bookingId);
        return Result.success(review);
    }
}